package com.lh.api.controller.shop;

import com.lh.api.controller.AbstractController;
import com.lh.api.service.ColumnService;
import com.lh.api.service.ShopService;
import com.lh.api.vo.ColumnVo;
import com.lh.api.vo.SearchVo;
import com.lh.api.vo.ShopDetailVo;
import com.lh.common.enums.ColumnTypeEnum;
import com.lh.common.enums.ShopSortTypeEnum;
import com.lh.common.enums.ShopTypeEnum;
import com.lh.common.entity.admin.Column;
import com.lh.common.enums.UpperLowerShelfStatus;
import com.lh.common.utils.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Xyw
 * @ClassName: ColumnAction
 * @Description: (栏目管理)
 * @date: 2020-06-29 11:07
 */

@Api(value="ColumnAction",tags={"栏目相关接口 v1.3"})
@RestController
@RequestMapping("/api/Column")
public class ColumnAction extends AbstractController {

    @Autowired
    private ShopService shopService;
    @Autowired
    private ColumnService columnService;

    @ApiOperation(value = "栏目列表 v1.3")
    @GetMapping(value = "/columnList")
    public Result<List<ColumnVo>> columnList(){
        List<ColumnVo> columnVos = columnService.columnList();
        return Result.ok(columnVos);
    }

    @ApiOperation(value = "栏目相关商品查询 v1.3")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "cid", value = "栏目id", required = true, dataTypeClass= Long.class),
            @ApiImplicitParam(paramType="query", name = "sortType", value = "商品排序类型：DEFAULT:默认 时间排序，PRICEDESC:价格从高到底，PRICEASC:价格从低到高 v1.3", required = false, dataTypeClass = ShopSortTypeEnum.class),
            @ApiImplicitParam(paramType="query", name = "qureyTime", value = "查询时间,形如:2020-03-01 21:00:00,查询第一页时不用传，由后端返回", required = false,dataTypeClass= Integer.class),
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "当前页", required = true,dataTypeClass= Integer.class),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "页数大小", required = true,dataTypeClass= Integer.class)
    })
    @GetMapping("/getColumnShopList")
    @ResponseBody
    public Result<SearchVo> getColumnShopList(Long cid, ShopSortTypeEnum sortType, String qureyTime, Integer pageNum, Integer pageSize){
        AssertUtil.assertNotNull(cid, Constant.RESULT.FI1000, "cid is required");
        if(pageNum != null && pageNum == 1){
            qureyTime = DateTimeUtil.getDateTime();
        }
        Column column = columnService.getColumnStatus(cid);
        if (column == null || column.getStatus().equals(UpperLowerShelfStatus.LOWERSHELF)){
            return Result.error("This column has no existed!");
        }
        PageUtils<SearchVo> searchVoPageUtils = columnService.getColumnShopList(cid, sortType, column.getType(), qureyTime, pageNum, pageSize);
        searchVoPageUtils.setQureyTime(qureyTime);
        return Result.ok(searchVoPageUtils);
    }
}
